﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ExtensionControls
{
    public class PersonExtensionGrid : ExtensionGrid<PersonViewModel, EPersonColumn>
    {
        public PersonExtensionGrid() : base() { }

        public void sayHello()
        {
            foreach (DataGridViewRow selectedRow in this.SelectedRows)
            {
                PersonViewModel personVM = (PersonViewModel)selectedRow.Cells[this.FindObjectIndex()].Value;
                MessageBox.Show(personVM.SayHello());
            }
        }

        public void updateRows()
        {
            int objectIndex = this.FindObjectIndex();

            foreach (DataGridViewRow selectedRow in this.SelectedRows)
            {
                List<object> data = new List<object>();

                for (int i = 0; i < selectedRow.Cells.Count; i++)
                {
                    if (i != objectIndex)
                    {
                        data.Add(selectedRow.Cells[i].Value);
                    }
                }
                PersonViewModel personVM = (PersonViewModel)selectedRow.Cells[objectIndex].Value;
                personVM.UpdateData(this.Collection.Columns, data);
            }
        }
    }
}
